﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Web.Security;

using System.Configuration;
using System.Web.Configuration;
using System.Net.Configuration;
using System.Web.Mail;
//using System.Net.Mail;
namespace gamexpert.member
{
    public partial class Payment : System.Web.UI.Page
    {
        List<TextBox> textboxes;
        DataSet1 ds;
        DataSet1TableAdapters.my_billshipinfoTableAdapter da;
        MembershipUser u;
        DataSet1.my_billshipinfoRow r;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!User.Identity.IsAuthenticated)
            {
                Response.Redirect("~/Login.aspx");
            }
            MembershipUser u = Membership.GetUser(User.Identity.Name);
            Guid userid = (Guid)u.ProviderUserKey;
            //Session["userid"] = userid.ToString();

            string onclick="onclick";
            string javascript="if(!confirm('The changes are not saved.Are you sure you want to cancel?'))return false;";
            btnCancel.Attributes.Add(onclick,javascript);
            btnCancel2.Attributes.Add(onclick,javascript);
            btnCancel3.Attributes.Add(onclick,javascript);
            btnCancel4.Attributes.Add(onclick,javascript);

            string javascript2 = "if(!confirm('The PAYMENT AMOUNT (S$'+document.getElementById('ctl00_ContentPlaceHolder1_amt').innerHTML+') will be deducted from your credit card. Are you sure you want to proceed?'))return false;";
            btnFinish.Attributes.Add(onclick, javascript2);

            amt.Attributes.Add("name", "amt");

            if (MultiView1.ActiveViewIndex == 3)
            {
                renderTable();
            }
            if (!IsPostBack)
            {

                MultiView1.ActiveViewIndex = 0;
                ds = new DataSet1();
                da = new gamexpert.DataSet1TableAdapters.my_billshipinfoTableAdapter();
                //u = Membership.GetUser(User.Identity.Name);
                //Guid userid=(Guid)u.ProviderUserKey;
                if (Session["order"] == null)
                {
                    da.FillByUserId(ds.my_billshipinfo,userid);
                    Session["order"] = ds;
                }
                else
                {
                    ds = (DataSet1)Session["order"];
                }
                if (ds.my_billshipinfo.Rows.Count > 0)
                {
                    r = (DataSet1.my_billshipinfoRow)ds.my_billshipinfo.Rows[0];
                    txtsfirstname.Text = r.sfirstname;
                    txtslastname.Text = r.slastname;
                    txtsemail.Text = r.semail;
                    txtsaddress.Text = r.saddress;
                    txtscity.Text = r.scity;
                    txtsstate.Text = r.sstate;
                    txtszip.Text = r.szip;
                    txtsphone.Text = r.sphone;

                    txtbfirstname.Text = r.bfirstname;
                    txtblastname.Text = r.blastname;
                    txtbemail.Text = r.bemail;
                    txtbaddress.Text = r.baddress;
                    txtbcity.Text = r.bcity;
                    txtbstate.Text = r.bstate;
                    txtbzip.Text = r.bzip;
                    txtbphone.Text = r.bphone;
                }
                else
                {
                    ds.my_billshipinfo.Addmy_billshipinfoRow(userid,"","","","","","","","","","","","","","","","","","");
                }
            }
        }

        protected void btnCancel_Click(object sender, EventArgs e)
        {
            Response.Redirect("~/member/MemberArea.aspx");
        }

      
        void addData()
        {
            //ds = (DataSet1)Session["order"];
            DataSet1 Dss = new DataSet1();
            da = new gamexpert.DataSet1TableAdapters.my_billshipinfoTableAdapter();
            u = Membership.GetUser(User.Identity.Name);
            Guid userid = (Guid)u.ProviderUserKey;
            da.FillByUserId(Dss.my_billshipinfo,userid);

            if (Dss.my_billshipinfo.Rows.Count <= 0)
            {
                Dss.my_billshipinfo.Addmy_billshipinfoRow(userid, txtsfirstname.Text, txtslastname.Text, txtsemail.Text, txtsaddress.Text, txtscity.Text, txtsstate.Text, cbobcountry.SelectedValue, txtszip.Text, txtsphone.Text, txtbfirstname.Text, txtblastname.Text, txtbemail.Text, txtbaddress.Text, txtbcity.Text, txtbstate.Text, cbobcountry.SelectedValue, txtbzip.Text, txtbphone.Text);
                da.Update(Dss.my_billshipinfo);
            }
            
        }

        protected void btnCancel_Click1(object sender, EventArgs e)
        {
            Response.Redirect("~/member/MemberArea.aspx");
        }

        protected void btnNext1_Click(object sender, EventArgs e)
        {
            DataSet1 dss = (DataSet1)Session["order"];
            r = (DataSet1.my_billshipinfoRow)dss.my_billshipinfo.Rows[0];
            r.bfirstname=txtbfirstname.Text;
            r.blastname=txtblastname.Text;
            r.bemail=txtbemail.Text;
            r.baddress=txtbaddress.Text;
            r.bcity=txtbcity.Text;
            r.bstate=txtbstate.Text;
            r.bzip=txtbzip.Text;
            r.bphone=txtbphone.Text;

            //da = new gamexpert.DataSet1TableAdapters.my_billshipinfoTableAdapter();
            //da.Update(dss.my_billshipinfo);
            MultiView1.ActiveViewIndex = 1;
        }

        protected void btnCancel2_Click(object sender, EventArgs e)
        {
            Response.Redirect("~/member/MemberArea.aspx");
        }

        protected void btnCancel3_Click(object sender, EventArgs e)
        {
            Response.Redirect("~/member/MemberArea.aspx");
        }

        protected void btnPrev1_Click(object sender, EventArgs e)
        {
            MultiView1.ActiveViewIndex = 0;
        }

        protected void btnNext2_Click(object sender, EventArgs e)
        {
            if (chkSame.Checked == true)
            {
                DataSet1 dss = (DataSet1)Session["order"];
                /*
                r = (DataSet1.my_billshipinfoRow)dss.my_billshipinfo.Rows[0];
                r.sfirstname = txtsfirstname.Text = txtbfirstname.Text;
                r.slastname = txtslastname.Text = txtblastname.Text;
                r.semail = txtsemail.Text = txtbemail.Text;
                r.saddress = txtsaddress.Text = txtbaddress.Text;
                r.scity = txtscity.Text = txtbcity.Text;
                r.sstate = txtsstate.Text = txtbstate.Text;
                r.szip = txtszip.Text = txtbzip.Text;
                r.sphone = txtsphone.Text = txtbphone.Text;
                Session["order"] = dss;
                 * */
                
                dss.my_billshipinfo.Rows[0]["sfirstname"] = txtsfirstname.Text = txtbfirstname.Text;
                dss.my_billshipinfo.Rows[0]["slastname"] = txtslastname.Text = txtblastname.Text;
                dss.my_billshipinfo.Rows[0]["semail"] = txtsemail.Text = txtbemail.Text;
                dss.my_billshipinfo.Rows[0]["saddress"] = txtsaddress.Text = txtbaddress.Text;
                dss.my_billshipinfo.Rows[0]["scity"] = txtscity.Text = txtbcity.Text;
                dss.my_billshipinfo.Rows[0]["sstate"] = txtsstate.Text = txtbstate.Text;
                dss.my_billshipinfo.Rows[0]["szip"] = txtszip.Text = txtbzip.Text;
                dss.my_billshipinfo.Rows[0]["sphone"] = txtsphone.Text = txtbphone.Text;
                Session["order"] = dss;
                MultiView1.ActiveViewIndex = 3;
            }
            else
            {
                MultiView1.ActiveViewIndex = 2;
            }
        }

        protected void btnCancel4_Click(object sender, EventArgs e)
        {
            Response.Redirect("~/member/MemberArea.aspx");
        }

        protected void btnPrev3_Click(object sender, EventArgs e)
        {
            if (chkSame.Checked == true)
            {
                MultiView1.ActiveViewIndex = 1;
            }
            else
            {
                MultiView1.ActiveViewIndex = 2;
            }
        }

        protected void btnPrev2_Click(object sender, EventArgs e)
        {
            MultiView1.ActiveViewIndex = 1;
        }
        protected void btnNext3_Click(object sender, EventArgs e)
        {
            DataSet1 dss = (DataSet1)Session["order"];
            r = (DataSet1.my_billshipinfoRow)dss.my_billshipinfo.Rows[0];
            r.sfirstname = txtsfirstname.Text;
            r.slastname = txtslastname.Text;
            r.semail = txtsemail.Text;
            r.saddress = txtsaddress.Text;
            r.scity = txtscity.Text;
            r.sstate = txtsstate.Text;
            r.szip = txtszip.Text;
            r.sphone = txtsphone.Text;
            MultiView1.ActiveViewIndex = 3;
        }
        void copyBilltoShip()
        {
            txtsfirstname.Text = txtbfirstname.Text;
            txtslastname.Text = txtblastname.Text;
            txtsemail.Text = txtbemail.Text;
            txtsaddress.Text = txtbaddress.Text;
            txtscity.Text = txtbcity.Text;
            txtsstate.Text = txtbstate.Text;
            cboscountry.SelectedValue = cbobcountry.SelectedValue;
            txtszip.Text = txtbzip.Text;
            txtsphone.Text = txtbphone.Text;
        }
        void DisplayInfo()
        {
            if (chkSame.Checked == true)
            {
                lblbfirstname.Text = txtbfirstname.Text;
                lblblastname.Text = txtblastname.Text;
                lblbemail.Text = txtbemail.Text;
                lblbaddress.Text = txtbaddress.Text;
                lblbcity.Text = txtbcity.Text;
                lblbstate.Text = txtbstate.Text;
                lblbcountry.Text = cbobcountry.SelectedValue;
                lblbzip.Text = txtbzip.Text;
                lblbphone.Text = txtbphone.Text;

                lblsfirstname.Text = txtbfirstname.Text;
                lblslastname.Text = txtblastname.Text;
                lblsemail.Text = txtbemail.Text;
                lblsaddress.Text = txtbaddress.Text;
                lblscity.Text = txtbcity.Text;
                lblsstate.Text = txtbstate.Text;
                lblscountry.Text = cbobcountry.SelectedValue;
                lblszip.Text = txtbzip.Text;
                lblsphone.Text = txtbphone.Text;
            }
            else
            {
                lblbfirstname.Text = txtbfirstname.Text;
                lblblastname.Text = txtblastname.Text;
                lblbemail.Text = txtbemail.Text;
                lblbaddress.Text = txtbaddress.Text;
                lblbcity.Text = txtbcity.Text;
                lblbstate.Text = txtbstate.Text;
                lblbcountry.Text = cbobcountry.SelectedValue;
                lblbzip.Text = txtbzip.Text;
                lblbphone.Text = txtbphone.Text;

                lblsfirstname.Text = txtsfirstname.Text;
                lblslastname.Text = txtslastname.Text;
                lblsemail.Text = txtsemail.Text;
                lblsaddress.Text = txtsaddress.Text;
                lblscity.Text = txtscity.Text;
                lblsstate.Text = txtsstate.Text;
                lblscountry.Text = cboscountry.SelectedValue;
                lblszip.Text = txtszip.Text;
                lblsphone.Text = txtsphone.Text;
            }
        }
        protected void MultiView1_ActiveViewChanged(object sender, EventArgs e)
        {
            if (MultiView1.ActiveViewIndex == 3)
            {
                DisplayInfo();
                renderTable();
            }
        }
        protected void btnFinish_Click(object sender, EventArgs e)
        {
            string orderdetail = "";
            addData();
            Cart c=(Cart)Session["cart"];
            
            localhost.Service1 s = new localhost.Service1();
            u = Membership.GetUser(User.Identity.Name);
            Guid userid = (Guid)u.ProviderUserKey;
            localhost.ResultData result;
            try
            {
               result = s.Payment(userid, ccname.Text, ccno.Text, Int32.Parse(ccmonth.Text), Int32.Parse(ccyear.Text), cvv.Text);
            }
            catch
            {
                result = new localhost.ResultData();
                result.ResultCode = 999;
            }
            if (result.ResultCode == 1)
            {
                DataSet1 dss = (DataSet1)Session["order"];
                r = (DataSet1.my_billshipinfoRow)dss.my_billshipinfo.Rows[0];
                decimal total = Decimal.Parse(c.finalTotal().ToString());
                dss.my_order.Addmy_orderRow(userid, r.sfirstname, r.slastname, r.semail, r.saddress, r.scity, r.sstate, r.scountry, r.szip, r.sphone, r.bfirstname, r.blastname, r.bemail, r.baddress, r.bcity, r.bstate, r.bcountry, r.bzip, r.bphone, 0, total);
                DataSet1TableAdapters.my_orderTableAdapter daa = new DataSet1TableAdapters.my_orderTableAdapter();
                daa.Update(dss.my_order);
                int? orderid = daa.orderid(userid);
                dss.my_order.Clear();
                daa.FillById(dss.my_order, (int)orderid);
                DataSet1.my_orderRow mor=(DataSet1.my_orderRow)dss.my_order.Rows[0];
                List<Product> ps = c.GetProductList();
                int i=1;
                orderdetail += "\nOrder ID: "+orderid+"\n\n";
                foreach (Product p in ps)
                {
                    dss.my_orderproduct.Addmy_orderproductRow(mor.id, p.Title, Decimal.Parse(p.Price.ToString()), Decimal.Parse(p.ShippingCost.ToString()), p.Qty,p.Id);
                    orderdetail+="\n("+i+") "+p.Title+"\t[S$"+p.Price+"]\t"+p.Qty+"pcs";
                    i++;
                }
                orderdetail += "\n---------------------------------------------";
                orderdetail += "\nTotal = [S$" + c.finalTotal().ToString()+"]";
                orderdetail += "\n---------------------------------------------";
                DataSet1TableAdapters.my_orderproductTableAdapter daa2 = new DataSet1TableAdapters.my_orderproductTableAdapter();
                daa2.Update(dss);

                //SEND MAIL
                Configuration configurationFile = WebConfigurationManager.OpenWebConfiguration("/gamexpert");
                MailSettingsSectionGroup mailSettings = (MailSettingsSectionGroup)configurationFile.GetSectionGroup("system.net/mailSettings");
                MailMessage msgMail = new MailMessage();
                //msgMail.To = u.Email+","+r.bemail;
                msgMail.To =r.bemail;
                msgMail.From = mailSettings.Smtp.From;
                msgMail.Bcc = mailSettings.Smtp.From;
                msgMail.Subject = "[Notification]Payment to GameXpert";
                msgMail.BodyFormat = MailFormat.Text;
                msgMail.Body = String.Format("Dear {0},\n\n\tWe have successfully received your payment.All the price are inclusive of GST.\n\nOrder details\n\n{1}\n\nThank you for shopping with us.\nRegards,\nGameXpert",User.Identity.Name,orderdetail);
                //msgMail.Attachments.Add(new MailAttachment("c:\\temp\\annual-report.pdf"));
                SmtpMail.SmtpServer = mailSettings.Smtp.Network.Host;//"137.132.244.140";
                try
                {
                    SmtpMail.Send(msgMail);
                }
                catch (Exception ex)
                {
                    //email cannot send
                    lblsuccess.Text = "Payment is successful. We will send an email invoice to your billing email soon.Thank you.";
                }
                c.RemoveAllProducts();
                MultiView1.ActiveViewIndex = 5;
            }
            else if (result.ResultCode == 100)
            {
                lblPaymentError.Text = "Your payment is unsuccessful. Please check your credit card information and try again.";
                MultiView1.ActiveViewIndex = 4;
            }
            else
            {
                lblPaymentError.Text = "Your payment is unsuccessful due to our technical problem. Sorry for inconvinent caused and please try again later.";
                MultiView1.ActiveViewIndex = 4;
            }
            
        }
        protected void btnOK_Click(object sender, EventArgs e)
        {
            Response.Redirect("~/member/MemberArea.aspx");
        }
        public void renderTable()
        {
            Cart c = (Cart)Session["cart"];
            List<Product> ps;
            ps = c.GetProductList();
            ps.Sort();
            if (ps.Count == 0)
            {
                Literal l = new Literal();
                l.Mode = LiteralMode.PassThrough;
                l.Text = "<p>There is no items in shopping cart.</p>";

                //LinkButton lb = new LinkButton();
                //lb.ID = "lbContinue";
                //lb.Text = "Continue shopping.";
                //lb.Click += new EventHandler(lbContinue_Click);
                Panel1.Controls.Add(l);
                //Panel1.Controls.Add(lb);
                //lbtnCheckout.Visible = false;
                //Label1.Visible = false;
            }
            Table1.Rows.Clear();
            int first = 0;
            textboxes = new List<TextBox>();
            foreach (Product p in ps)
            {
                DataSet ds = DataBroker.getProductById(p.Id);
                p.Title = ds.Tables[0].Rows[0]["title"].ToString();
                p.Price = Double.Parse(ds.Tables[0].Rows[0]["price"].ToString());
                p.ShippingCost = Double.Parse(ds.Tables[0].Rows[0]["shippingcost"].ToString());
                if (first == 0)
                {
                    TableHeaderRow trh = new TableHeaderRow();
                    TableHeaderCell tdt1 = new TableHeaderCell();
                    TableHeaderCell tdt2 = new TableHeaderCell();
                    TableHeaderCell tdt21 = new TableHeaderCell();
                    TableHeaderCell tdt3 = new TableHeaderCell();
                    TableHeaderCell tdt4 = new TableHeaderCell();
                    TableHeaderCell tdt5 = new TableHeaderCell();
                    tdt1.Text = "Product Title";
                    tdt2.Text = "Price(S$)";
                    tdt21.Text = "Shipping Cost<br/> per item(S$)";
                    tdt3.Text = "Quantity";
                    tdt4.Text = "Total Amount";
                    tdt5.Text = "Action";
                    trh.Cells.Add(tdt1);
                    trh.Cells.Add(tdt2);
                    trh.Cells.Add(tdt21);
                    trh.Cells.Add(tdt3);
                    trh.Cells.Add(tdt4);
                    trh.Cells.Add(tdt5);
                    Table1.Rows.Add(trh);
                }

                TableRow tr = new TableRow();
                //first cell
                TableCell td = new TableCell();
                //td.Text = p.Id.ToString();
                td.Text = p.Title.ToString();
                tr.Cells.Add(td);

                //Second cell
                TableCell td2 = new TableCell();
                //td.Text = p.Id.ToString();
                td2.Text = String.Format("S${0:f2}", p.Price);
                tr.Cells.Add(td2);

                TableCell td21 = new TableCell();
                //td.Text = p.Id.ToString();
                td21.Text = String.Format("S${0:f2}", p.ShippingCost);
                tr.Cells.Add(td21);

                //third cell
                TableCell td3 = new TableCell();
                //td2.Text = p.Qty.ToString();
                TextBox tb = new TextBox();
                tb.ID = "p_" + p.Id;
                tb.Text = p.Qty.ToString();
                tb.ToolTip = p.Id.ToString();
                tb.Attributes.Add("onblur", "if(!/^[0-9]+$/.test(this.value)){alert('Please fill in valid quantity');this.value='" + tb.Text + "';this.focus();}");
                textboxes.Add(tb);
                td3.Controls.Add(tb);
                tr.Cells.Add(td3);

                //five cell
                TableCell td5 = new TableCell();
                td5.Text = String.Format("S${0:f2}", p.Total());
                tr.Cells.Add(td5);

                //forth cell
                TableCell td4 = new TableCell();
                LinkButton lb = new LinkButton();
                lb.ID = "lbtn_" + p.Id;
                lb.Text = "remove";
                lb.Click += new EventHandler(lb_Click);
                lb.CommandName = "Remove";
                lb.CommandArgument = p.Id.ToString();
                td4.Controls.Add(lb);
                tr.Cells.Add(td4);

                Table1.Rows.Add(tr);
                first++;
            }
            if (first > 0)
            {

                //update btn
                TableRow tru = new TableRow();
                TableCell tdu1 = new TableCell();
                TableCell tdu2 = new TableCell();
                TableCell tdu21 = new TableCell();
                TableCell tdu3 = new TableCell();
                TableCell tdu4 = new TableCell();
                TableCell tdu5 = new TableCell();
                tdu1.Text = "";// "Product Title";
                tdu2.Text = "";
                tdu21.Text = "";
                //tdf3.Text = "Total";// "Quantity";
                Button btnUpdate = new Button();
                btnUpdate.ID = "btnUpdate";
                btnUpdate.Text = "Update";
                btnUpdate.CssClass = "btnUpdate";
                btnUpdate.Click += new EventHandler(btnUpdate_Click);
                tdu3.Controls.Add(btnUpdate);
                tdu4.Text = "";// "S$" + c.Total().ToString();// "Total Amount";
                tdu5.Text = "";// "Action";
                tru.Cells.Add(tdu1);
                tru.Cells.Add(tdu2);
                tru.Cells.Add(tdu21);
                tru.Cells.Add(tdu3);
                tru.Cells.Add(tdu4);
                tru.Cells.Add(tdu5);
                Table1.Rows.Add(tru);



                /*
               //footer
               TableRow trf = new TableRow();
               trf.CssClass = "lastrow";
               //TableCell tdf1 = new TableCell();
               //TableCell tdf2 = new TableCell();
               TableCell tdf3 = new TableCell();
               TableCell tdf4 = new TableCell();
               TableCell tdf5 = new TableCell();
               //tdf1.Text = "";// "Product Title";
               //tdf2.Text = "";
               tdf3.ColumnSpan = 4;
               tdf3.HorizontalAlign = HorizontalAlign.Right;
               tdf3.Text = "Total before shipping cost = ";// "Quantity";
               tdf4.Text = "S$"+c.Total().ToString();// "Total Amount";
               tdf5.Text = "";// "Action";
               //trf.Cells.Add(tdf1);
               //trf.Cells.Add(tdf2);
               trf.Cells.Add(tdf3);
               trf.Cells.Add(tdf4);
               trf.Cells.Add(tdf5);
               Table1.Rows.Add(trf);


               //footer2
               TableRow trf2 = new TableRow();
               trf2.CssClass = "lastrow";
               //TableCell tdf21 = new TableCell();
               //TableCell tdf22 = new TableCell();
               TableCell tdf23 = new TableCell();
               TableCell tdf24 = new TableCell();
               TableCell tdf25 = new TableCell();
               //tdf21.Text = "";// "Product Title";
               //tdf22.Text = "";
               tdf23.HorizontalAlign = HorizontalAlign.Right;
               tdf23.ColumnSpan = 4;
               tdf23.Text = "Total shipping cost= ";// "Quantity";
               tdf24.Text = "S$" + c.TotalShippingCost().ToString();// "Total Amount";
               tdf25.Text = "";// "Action";
               //trf2.Cells.Add(tdf21);
               //trf2.Cells.Add(tdf22);
               trf2.Cells.Add(tdf23);
               trf2.Cells.Add(tdf24);
               trf2.Cells.Add(tdf25);
               Table1.Rows.Add(trf2);
               */
                //footer3
                TableRow trf3 = new TableRow();
                trf3.CssClass = "lastrow";
                TableCell tdf31 = new TableCell();
                TableCell tdf32 = new TableCell();
                TableCell tdf321 = new TableCell();
                TableCell tdf33 = new TableCell();
                TableCell tdf34 = new TableCell();
                TableCell tdf35 = new TableCell();
                tdf31.Text = "";// "Product Title";
                tdf32.Text = "";
                tdf321.Text = "";
                tdf33.HorizontalAlign = HorizontalAlign.Right;
                tdf33.Text = "Total= ";// "Quantity";
                tdf34.Text = "S$" + c.finalTotal().ToString();// "Total Amount";
                amt.Text = c.finalTotal().ToString();
                tdf35.Text = "";// "Action";
                trf3.Cells.Add(tdf31);
                trf3.Cells.Add(tdf32);
                trf3.Cells.Add(tdf321);
                trf3.Cells.Add(tdf33);
                trf3.Cells.Add(tdf34);
                trf3.Cells.Add(tdf35);
                Table1.Rows.Add(trf3);
            }
        }
        protected void lbtnEditBilling_Click(object sender, EventArgs e)
        {
            MultiView1.ActiveViewIndex = 0;
        }
        protected void lbtnEditShipping_Click(object sender, EventArgs e)
        {
            MultiView1.ActiveViewIndex = 1;
        }
        protected void btnUpdate_Click(object sender, EventArgs e)
        {
            Cart c = (Cart)Session["cart"];
            List<Product> ps;
            ps = c.GetProductList();
            foreach (TextBox tb in textboxes)
            {
                Product p = c.FindProductById(Int32.Parse(tb.ToolTip));
                p.Qty = Int32.Parse(tb.Text);
            }
            Literal1.Text = "<p>Successfully updated items quantity</p>";
            renderTable();
        }
        protected void lb_Click(object sender, EventArgs e)
        {
            LinkButton lb = (LinkButton)sender;
            if (lb.CommandName == "Remove")
            {
                int id = Int32.Parse(lb.CommandArgument.ToString());
                Cart c = (Cart)Session["cart"];
                c.RemoveProductById(id);
                Session["cart"] = c;
                Literal1.Text = "<p>Items successfully removed.</p>";
                renderTable();
            }
        }
        protected void btnErrorOK_Click(object sender, EventArgs e)
        {
            MultiView1.ActiveViewIndex = 3;
        }
    }
}
